package com.kitking.app3;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class MyBroadcastReceiver extends BroadcastReceiver {
//接收广播，静态的。自定义广播内容
    TextView textView;

    public MyBroadcastReceiver(TextView textView) {
        this.textView = textView;
    }

    @Override
    public void onReceive(Context context, Intent intent) {


        if (intent !=null){
            String action=intent.getAction();
            Toast.makeText(context,"自定义广播测试!!!",Toast.LENGTH_LONG).show();
            Log.d("Tag------","自定义广播测试.........."+action);
            //判断是什么广播，是不是我们自定义的广播
            if (TextUtils.equals(action,MainActivity.MY_ACTION)){
                String content=intent.getStringExtra("broadcastcontent");
                if (textView!=null){
                    textView.setText("接收到的是"+content);
                }
            }
        }
    }
}